package com.example.kafka.producer;

import com.alibaba.fastjson.JSON;
import com.example.kafka.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class KafkaProducer {

    @Resource
    private KafkaTemplate kafkaTemplate;

    /**
     * 发送数据
     * @param
     */
    public void send() {
//        IndexDataPo indexData = new IndexDataPo();
//        String indexData = FileUtil.fileReaderByScanner(new File("C:\\Users\\shen\\Desktop\\省调控智慧运维项目\\test.json"));
        Map<String,String> map = new HashMap<>();
//        map.put("employee","jerry");
//        map.put("status","offline");
//        map.put("event_timestamp",timestamp);
//        String data = JSON.toJSONString(map);
//        System.err.println(data);
//        while (true){
//            Long timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
//            String data = "{\"employee\":\"jerry\",\"status\":\"offline\",\"event_timestamp\":\""+timestamp+"\"}";
//            System.err.println("发送用户日志数据:" + data);
//
//            kafkaTemplate.send("test5", "数据", data);
//            System.err.println("发送成功");
//
//            try {
//                Thread.sleep(10000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }

    }
}
